import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loxen/routes/routes.dart';
import 'package:loxen/utils/config.dart';

import 'dialog.style.dart';

class ShowPolicyDialog extends StatelessWidget {
  final bool showButton;

  const ShowPolicyDialog({Key key, this.showButton = true}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Material(
      type: MaterialType.transparency,
      child: Center(
        child: Container(
          width: 500.w,
          height: 600.h,
          color: Theme.of(context).backgroundColor,
          child: Column(
            children: <Widget>[
              Padding(
                padding: EdgeInsets.only(top: 30.h),
                child: Text(
                  '服务协议和隐私政策',
                  style: DialogStyle.titleStyle,
                ),
              ),
              Expanded(
                  child: SingleChildScrollView(
                    child: Container(
                      padding: EdgeInsets.fromLTRB(20.w, 20.h, 20.w, 20.w),
                      child: RichText(
                        text: TextSpan(
                          text:
                          '''   请你务必审慎阅读，充分理解“服务协议”和“隐私政策”个条款，包括但不限于：为了向你提供内容分享等服务，我们需要收集你的设备信息、个人信息等。你可以在“我的”界面中查看、变更、删除个人信息。
    你可以阅读''',
                          style: DialogStyle.textStyle,
                          children: <TextSpan>[
                            TextSpan(
                                text: '《用户协议》',
                                style: DialogStyle.navStyle,
                                recognizer: TapGestureRecognizer()
                                  ..onTap = () => Navigator.of(context)
                                      .pushNamed(Routes.agreement)
                            ),
                            TextSpan(
                              text: ' 和 ',
                              style: DialogStyle.textStyle,
                            ),
                            TextSpan(
                                text: '《隐私政策》',
                                style: DialogStyle.navStyle,
                                recognizer: TapGestureRecognizer()
                                  ..onTap = () {
                                    Navigator.of(context).pushNamed(Routes.policy);
                                  }),
                            TextSpan(
                              text: '了解详细信息。如你同意，请点击“同意”开始接受我们的服务。',
                              style: DialogStyle.textStyle,
                            )
                          ],
                        ),
                      ),
                    ),
                  )),
              Divider(
                height: 0,
              ),
              showButton
                  ? Row(
                children: <Widget>[
                  Expanded(
                    child: Container(
                        height: 100.h,
                        child: Center(
                          child: InkWell(
                            onTap: () {
                              Navigator.pop(context, false);
                            },
                            child: Text(
                              '暂不使用',
                              style: TextStyle(
                                  fontSize: 28.sp,
                                  color: Color(0xFF82868E)),
                            ),
                          ),
                        )),
                  ),
                  Expanded(
                    child: Container(
                        height: 100.h,
                        child: Center(
                          child: InkWell(
                            onTap: () async {
                              Navigator.pop(context, true);
                            },
                            child: Text(
                              '同意',
                              style: TextStyle(
                                  fontSize: 28.sp,
                                  color: Color(0xFF0CABCB)),
                            ),
                          ),
                        )),
                  )
                ],
              )
                  : InkWell(
                onTap: () {
                  Navigator.pop(context);
                },
                child: Container(
                  height: 100.h,
                  child: Center(
                    child: Text(
                      '确定',
                      style:
                      TextStyle(fontSize: 28.sp, color: Colors.black),
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
